<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="lijinbo" />
    <title>搭建nodejs接口服务器</title>
    <style></style>
  </head>

  <body>
    <div class="box">hello</div>
    <button id="getBtn">get 请求</button>
    <button id="postBtn">post 请求</button>

    <script>
      document.getElementById('getBtn').onclick = async function () {
        const res = await fetch('/api/list')
        const list = await res.json()
        console.log(list, '-->>> list')
      }
      document.getElementById('postBtn').onclick = async function () {
        const data = {
          a: 1,
          b: 2
        }
        const res = await fetch('/getUserInfo', {
          method: 'post',
          body: JSON.stringify(data),
          headers: { 'Content-Type': 'application/json' }
        })
        const info = await res.json()
        console.log(info, '-->>> info')
      }
    </script>
  </body>
</html>
